package org.apache.ocean.transaction;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import org.apache.ocean.CLong;

public class MultiLevelMap {
  int maxLevel2 = 5;
  Level level1;
  List<Level> level2List = new ArrayList<Level>();
	
	public MultiLevelMap(int maxLevel2) {
		this.maxLevel2 = maxLevel2;
	}
	
	public void add(Set<CLong> added, Set<CLong> deleted) {
		Level level = new Level(added, deleted);
		if (level1 == null) level1 = level;
		else { 
			level2List.add(level);
		}
		maybeMerge();
	}
	
	public MultiLevelMap copy() {
		MultiLevelMap multiLevelMap = new MultiLevelMap(maxLevel2);
		return multiLevelMap;
	}
	
	public boolean contains(CLong id) {
		if (level1 != null) {
			if (level1.contains(id)) return true;
		}
		for (Level level2 : level2List) {
			if (level2.contains(id)) return true;
		}
		return false;
	}
	
	public static class Level {
		Set<CLong> added;
		Set<CLong> deleted;
		
		public Level(Set<CLong> added, Set<CLong> deleted) {
			this.added = added;
			this.deleted = deleted;
		}
		
		public boolean contains(CLong id) {
			if (added.contains(id)) return true;
			else return false;
		}
	}
	
	public void maybeMerge() {
		
	}
}
